﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ThreeByte.ActiveDeck.Config;
using System.Windows.Forms.Integration;

namespace ThreeByte.ActiveDeck.Controls
{
    public partial class PublishForm : Form
    {
        private PublishControl _publishControl;

        public PublishForm(CoreConfig config) {
            InitializeComponent();

            //Used to signal that the publication should stop
            this.FormClosing += new FormClosingEventHandler(PublishForm_FormClosing);
            _publishControl = new PublishControl(config);

            _publishControl.Close += new EventHandler(publishControl_Close);
            
            //Add Setup Form
            ElementHost elementHost = new ElementHost();
            elementHost.Dock = DockStyle.Fill;
            elementHost.Location = new Point(0, 0);
            elementHost.Name = "elementHost";
            elementHost.Child = _publishControl;
            this.Controls.Add(elementHost);
            
        }

        void PublishForm_FormClosing(object sender, FormClosingEventArgs e) {
            e.Cancel = _publishControl.SendCancel();
            ErrorMessage = _publishControl.ErrorMessage;
        }

        public string ErrorMessage { get; private set; }
        void publishControl_Close(object sender, EventArgs e) {
            Close();
        }

    }
}
